package router

import (
	"awesomeProject2/api"
	"awesomeProject2/config"
	"awesomeProject2/middleware"
	"github.com/gin-gonic/gin"
	"net/http"
)

func InitRouter() { //可以返回一个*gin.Engine
	gin.SetMode(config.AppMode)
	r := gin.Default()

	r.StaticFS(config.GVA_CONFIG_Upload_Path, http.Dir(config.GVA_CONFIG_Upload_Path)) // 为用户头像和文件提供静态地址
	if config.AppMode == "release" {
		//r.Use(middleware.Cors())                                                           // 跨域中间件
		r.Use(middleware.GinRecovery(true)) // Recover中间件打印堆栈
	}

	routerAuth := r.Group("")
	routerAuth.Use(middleware.JWTAuthMiddleware()) // 下面的路由对应函数需要有token
	{
		// User模块路由接口
		routerAuth.PUT("user", api.UpdateTeacher)
		routerAuth.DELETE("user/:id", api.DeleteTeacher)
		routerAuth.POST("user", api.CreateTeacher)
		routerAuth.GET("teacher", api.GetTeacher)
		routerAuth.GET("papertoshow", api.GetPaperToShow)
		routerAuth.GET("projecttoshow", api.GetProjectToShow)
		routerAuth.GET("worktoshow", api.GetWorkToShow)
		routerAuth.GET("patenttoshow", api.GetPatentToShow)
		routerAuth.GET("achievementtoshow", api.GetAchievementToShow)
		routerAuth.GET("index", api.GetTeacherInfo)
		routerAuth.POST("password", api.ChangePasswd)
		routerAuth.GET("papertoshowadmin/:id", api.GetPaperToShowAdmin)
		routerAuth.GET("projecttoshowadmin/:id", api.GetProjectToShowAdmin)

		//achievement
		routerAuth.PUT("achievement", api.UpdateAchievement)
		routerAuth.DELETE("achievement/:id", api.DeleteAchievement)
		routerAuth.POST("achievement", api.CreateAchievement)
		routerAuth.GET("achievement/:id", api.GetAchievement)
		routerAuth.GET("achievementList", api.GetAchievements)
		routerAuth.PUT("achievementauth/:id", api.ChangeAchievementVisiblity)
		routerAuth.GET("achievements/:year", api.GetAllAchievements)
		routerAuth.GET("achievementdy", api.GetAchievementsDynamic)
		routerAuth.GET("achievementshowindex", api.GetAllAchievementsWithouYear)
		//papent
		routerAuth.PUT("patent", api.UpdatePatent)
		routerAuth.POST("patent", api.CreatePatent)
		routerAuth.DELETE("patent/:id", api.DeletePatent)
		routerAuth.GET("patent/:id", api.GetPatent)
		routerAuth.GET("patentList", api.GetPatents)
		routerAuth.PUT("patentauth/:id", api.ChangePatentVisiblity)
		routerAuth.GET("patents/:year", api.GetAllPatens)
		routerAuth.GET("patentdy", api.GetPatentsDynamic)
		routerAuth.GET("patentshowindex", api.GetAllPaperWithoutYear)
		//paper
		routerAuth.PUT("paper", api.UpdatePaper)
		routerAuth.POST("paper", api.CreatePaper)
		routerAuth.DELETE("paper/:id", api.DeletePaper)
		routerAuth.GET("paper/:id", api.GetPaper)
		routerAuth.GET("paperList", api.GetPapers) //分页查找
		routerAuth.PUT("paperauth/:id", api.ChangePaperVisiblity)
		routerAuth.GET("papers/:year", api.GetAllPapers)
		routerAuth.GET("paperdy", api.GetPapersDynamic)
		routerAuth.GET("papershowindex", api.GetAllPaperWithoutYear)

		//project
		routerAuth.PUT("project", api.UpdateProject)
		routerAuth.POST("project", api.CreateProject)
		routerAuth.DELETE("project/:id", api.DeleteProject)
		routerAuth.GET("project/:id", api.GetProject)
		routerAuth.GET("projectList", api.GetProjects)
		routerAuth.GET("projectListByLevel", api.GetProjectByLevel)
		routerAuth.GET("projectOngoing", api.GetAllOngoingProjects)
		routerAuth.PUT("projectauth/:id", api.ChangeProjectVisiblity)
		routerAuth.GET("projects/:year", api.GetAllProjects)
		routerAuth.GET("projectsbq/:year", api.GetAllProjectsbq)
		routerAuth.GET("projectdy", api.GetProjectsDynamic)
		routerAuth.GET("projectshowindex", api.GetAllProjectsWithoutyear)
		//work
		routerAuth.PUT("work", api.UpdateWork)
		routerAuth.POST("work", api.CreateWork)
		routerAuth.DELETE("work/:id", api.DeleteWork)
		routerAuth.GET("work/:id", api.GetWork)
		routerAuth.GET("workList", api.GetWorks)
		routerAuth.PUT("workauth/:id", api.ChangeWorkVisiblity)
		routerAuth.GET("works/:year", api.GetAllWorks)
		routerAuth.GET("workdy", api.GetWorksDynamic)
		routerAuth.GET("workshowindex", api.GetAllWorksWithoutYear)
		//data
		routerAuth.GET("AllNumber/:year", api.GetAllNumber)
		routerAuth.GET("paperinfo/:year", api.GetAllPaperInfo)
		routerAuth.GET("patentinfo/:year", api.GetAllPatentInfo)
		routerAuth.GET("achievementinfo/:year", api.GetAllAcInfo)
		routerAuth.GET("projectinfo/:year", api.GetAllPjInfo)
		routerAuth.GET("workinfo/:year", api.GetAllWKInfo)
		routerAuth.GET("workfiveinfo/:year", api.GetFiveInfo)
		routerAuth.GET("personinfo", api.GetPersonInfo)
		routerAuth.GET("personinfoadmin/:id", api.GetPersonInfoAdmin)
		routerAuth.GET("allinfoadmin/:id", api.GetAllInfoAdmin)
		routerAuth.GET("allinfo", api.GetAllInfo)
		routerAuth.GET("patentchartadmin/:id", api.GetPersonPatentAdmin)
		routerAuth.GET("patentchart", api.GetPersonPatent)
		routerAuth.GET("projectchartadmin/:year", api.GetAllPjMoney)
		routerAuth.GET("projectchar/:year", api.GetAllPjMoneyPerson)
		routerAuth.GET("projectcharadmin/:id/:year", api.GetAllPjMoneyPersonClickByAdmin)
		//config
		routerAuth.PUT("updateyear/:year", api.UpadateYear)
		routerAuth.GET("score/:year", api.GetScore)

	}

	routerPublic := r.Group("") //下面的路由不需要鉴权
	{
		//routerPublic.GET("achievements", api.GetAllAchievements)
		routerPublic.POST("login", api.Login)
		routerPublic.GET("userinfo/:id", api.GetTeacher)
		routerPublic.POST("upload", api.Upload)
		routerPublic.GET("users", api.GetAllTeachers)

	}

	_ = r.Run(config.HttpPort)
}
